package com.fox0g.filter;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
//中值平均滤波法

@Service
public class ValueAveragingFiltering {
    public static List<Double> applyValueAveragingFiltering(List<Double> data, int windowSize) {
        List<Double> filteredData = new ArrayList<>();

        // Handle the first few data points
        for (int i = 0; i < windowSize - 1; i++) {
            filteredData.add(data.get(i));
        }

        // Apply value averaging filtering
        for (int i = windowSize - 1; i < data.size(); i++) {
            double sum = 0.0;
            for (int j = i - windowSize + 1; j <= i; j++) {
                sum += data.get(j);
            }
            double average = sum / windowSize;
            filteredData.add(average);
        }

        return filteredData;
    }
}

